import java.util.Scanner;


public class Mini {

	static char[][] minePool= { {' ','*',' ',' ','*'},
								{'*',' ',' ','*',' '},
								{' ','*','*',' ',' '},
								{'*',' ',' ','*',' '},
								{' ','*','*',' ',' '}
		
			};
	
	static String[][] ourViewOfMinePool = new String[5][5];
	
	
	public static int checkForMines(int row, int col, char[][] arr){
		int mineCounter = 0;
		if(arr[row][col]=='*'){
			System.out.println("Uceli mina, krai na igrata.");
			return 0;
		}
		
		if(col+1 <arr[0].length && arr[row][col+1] == '*'){
				mineCounter++;
			}
		if(col+1 <arr[0].length && row - 1 >=0 && arr[row-1][col+1] == '*'){
			mineCounter++;
		}
		if(row -1 >= 0 && arr[row-1][col] == '*'){
			mineCounter++;
		}
		if(col-1 >= 0 && row - 1 >= 0 && arr[row-1][col-1] == '*'){
			mineCounter++;
		}
		if(col-1 >= 0 && arr[row][col-1]=='*'){
			mineCounter++;
		}
		if(col-1 >=0 && row+1 < arr.length && arr[row+1][col-1] == '*'){
			mineCounter++;
		}
		if(row+1 <arr.length && arr[row+1][col]=='*'){
			mineCounter++;
		}
		if(row+1 < arr.length && col+1 <arr[0].length && arr[row+1][col+1]=='*'){
			mineCounter++;
		}
		
		return mineCounter;
	}
	
	static void printOurMatrix(String[][] matrix){
		for (int i = 0; i < matrix.length; i++) {
			System.out.println("");
			for (int j = 0; j < matrix[0].length; j++) {
				System.out.print(matrix[i][j]+"|");
			}
		}
	}
	
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		
		while(true){
			System.out.println("Vyvedete red: ");
			int row = scanner.nextInt();
			if(row>=minePool.length){
				System.out.println("Nqma takyv red!");
				return;
			}
			
			System.out.println("Vyvedete kolona: ");
			int col = scanner.nextInt();
			if(col>=minePool[0].length){
				System.out.println("Nqma takava kolona!");
				return;
			}
			
		ourViewOfMinePool[row][col] = "  " +Integer.toString(checkForMines(row, col, minePool));
		printOurMatrix(ourViewOfMinePool);
		System.out.println();
		}
	}

}
